class QuestionsController < ApplicationController
  before_filter :find_person
  
  def index
    _questions = Question.actual(@person)
    @question = params[:pos].blank? ? _questions.first : _questions.find_by_position(params[:pos])
    
    #render :template => 'questions/next' if @question.nil?
    redirect_to people_path if Date.today > Date.parse("2012-01-28") || @question.nil?
  end
  
  def create
    @question = Question.actual(@person).find(params[:id])
    
    answer = @person.answers.new
    answer.answer_id = params[:answer][:variant]
    answer.question = @question
    answer.request_ip = request.remote_ip
    answer.user_agent = request.user_agent
    
    answer.save
    
    redirect_to questions_path
  end
  
  protected
    
    def find_person
      redirect_to root_path unless person_signed_in?
      @person = current_person
    end
end
